import 'package:base/main.dart';
import 'package:flutter/material.dart';
import 'package:framework/main.dart';
import 'package:module_discover/pages/filter_domain/filter_domain_logic.dart';
import 'package:module_discover/pages/model/domain_title_model.dart';

class DomainCategoryWidget extends StatelessWidget {
  final FilterDomainLogic logic;

  const DomainCategoryWidget({super.key, required this.logic});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: Constants.domain_left_width,
      color: Colors.transparent,
      child: Obx(() => ListView.builder(
            physics: BouncingScrollPhysics(),
            itemCount: logic.domainTitles.length,
            itemBuilder: (context, index) => _buildCategoryItem(logic, index),
          )),
    );
  }

  // 分类项组件
  Widget _buildCategoryItem(FilterDomainLogic logic, int index) {
    return InkWell(
      onTap: () => logic.selectedCategoryIndex(index),
      child: Obx(() {
        DomainTitleModel model = logic.domainTitles[index].value;
        int size =
            logic.filterPreviewVM.getSelectedChildSizeByParentKey(model.key);
        return Container(
          color: index == logic.selectedIndex.value
              ? JColor.color_f3f3f3
              : Colors.white,
          padding: EdgeInsets.symmetric(vertical: 8),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              size > 0
                  ? Text('* ', style: TextStyle(color: Colors.red))
                  : Text('* ', style: TextStyle(color: Colors.transparent)),
              Text(
                model.name,
                style: TextStyle(
                  color: Colors.black87,
                  fontSize: 12,
                  fontWeight: FontWeight.normal,
                ),
              )
            ],
          ),
        );
      }),
    );
  }
}
